package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.LineTechBigType;
import com.sailfish.springbootdemo.pojo.db1.LineTechSmallType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface LineTechSmallTypeDao {

    /**
     * 根据 大类 查询所有
     *
     * @param searchValue
     * @param lineTechBigTypeId
     * @return
     */
    @Results(id = "lineTechSmallTypeResultMap", value = {
            @Result(column = "line_tech_small_type_id", property = "lineTechSmallTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "line_tech_small_type_name", property = "lineTechSmallTypeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "line_tech_big_type_id", property = "lineTechBigTypeId", jdbcType = JdbcType.INTEGER),
    })
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_TECH_SMALL_TYPE + " where 1 = 1 " +
            "<if test='searchValue != null and searchValue != \"\" '>" +
            " and line_tech_small_type_name like CONCAT('%',#{searchValue},'%')" +
            "</if>" +
            "<if test='lineTechBigTypeId != null and lineTechBigTypeId != \"\" '>" +
            " and line_tech_big_type_id = #{lineTechBigTypeId}" +
            "</if>" +
            " order by sort" +
            "</script>")
    List<LineTechSmallType> getAllLineTechSmallTypeByBigType(@Param("searchValue") String searchValue, @Param("lineTechBigTypeId") Integer lineTechBigTypeId);

    @ResultMap(value = "lineTechSmallTypeResultMap")
    @Select("select * from " + DB1TableName.LINE_TECH_SMALL_TYPE + " where line_tech_small_type_name = #{lineTechSmallTypeName} and line_tech_big_type_id = #{lineTechBigTypeId}")
    List<LineTechSmallType> getLineTechSmallTypeByNameAndBigType(@Param("lineTechSmallTypeName") String lineTechSmallTypeName, @Param("lineTechBigTypeId") Integer lineTechBigTypeId);

    /**
     * 根据id查询
     *
     * @param lineTechSmallTypeId
     * @return
     */
    @Select("select * from " + DB1TableName.LINE_TECH_SMALL_TYPE + " where line_tech_small_type_id = #{lineTechSmallTypeId}")
    @ResultMap(value = "lineTechSmallTypeResultMap")
    LineTechSmallType getLineTechSmallTypeById(@Param("lineTechSmallTypeId") Integer lineTechSmallTypeId);

    /**
     * 判断有没有重复的
     *
     * @return
     */
    @ResultMap(value = "lineTechSmallTypeResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_TECH_SMALL_TYPE + " where line_tech_small_type_name = #{lineTechSmallTypeName} and line_tech_big_type_id = #{lineTechBigTypeId} " +
            "<if test='lineTechSmallTypeId != null and lineTechSmallTypeId != \"\" '>" +
            " and line_tech_small_type_id != #{lineTechSmallTypeId}" +
            "</if>" +
            "</script>")
    List<LineTechBigType> judgeUniqueLineTechSmallType(@Param("lineTechBigTypeId") Integer lineTechBigTypeId, @Param("lineTechSmallTypeId") Integer lineTechSmallTypeId, @Param("lineTechSmallTypeName") String lineTechSmallTypeName);


    /**
     * 新增
     *
     * @param lineTechSmallType
     * @return
     */
    @Insert("insert into " + DB1TableName.LINE_TECH_SMALL_TYPE + "(line_tech_small_type_name,status,sort,create_time,line_tech_big_type_id) values " +
            "(#{lineTechSmallType.lineTechSmallTypeName},#{lineTechSmallType.status},#{lineTechSmallType.sort},#{lineTechSmallType.createTime},#{lineTechSmallType.lineTechBigTypeId})")
    Integer addLineTechSmallType(@Param("lineTechSmallType") LineTechSmallType lineTechSmallType);

    /**
     * 更新
     *
     * @param lineTechSmallType
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.LINE_TECH_SMALL_TYPE +
            "<set>" +
            "<if test='lineTechSmallType.lineTechSmallTypeName != null and lineTechSmallType.lineTechSmallTypeName != \"\" '>" +
            " line_tech_small_type_name = #{lineTechSmallType.lineTechSmallTypeName}," +
            "</if>" +
            "<if test='lineTechSmallType.lineTechBigTypeId != null and lineTechSmallType.lineTechBigTypeId != \"\" '>" +
            " line_tech_big_type_id = #{lineTechSmallType.lineTechBigTypeId}," +
            "</if>" +
            "<if test='lineTechSmallType.sort != null and lineTechSmallType.sort != \"\" '>" +
            " sort = #{lineTechSmallType.sort}," +
            "</if>" +
            "<if test='lineTechSmallType.updateTime != null '>" +
            " update_time = #{lineTechSmallType.updateTime}," +
            "</if>" +
            "</set>" +
            " where line_tech_small_type_id = #{lineTechSmallType.lineTechSmallTypeId}" +
            "</script>")
    Integer updateLineTechSmallType(@Param("lineTechSmallType") LineTechSmallType lineTechSmallType);

    /**
     * 删除
     *
     * @param lineTechSmallTypeId
     * @return
     */
    @Delete("delete from " + DB1TableName.LINE_TECH_SMALL_TYPE + " where line_tech_small_type_id = #{lineTechSmallTypeId}")
    Integer deleteLineTechSmallType(@Param("lineTechSmallTypeId") Integer lineTechSmallTypeId);
}
